package com.levi.interceptor;

import com.levi.constants.MallConstants;
import com.levi.exception.UserLoginException;
import com.levi.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author shentong
 * @since 2022/3/24 8:49 PM
 */
@Slf4j
public class UserLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("进入用户拦截器！！！");
        User user = (User) request.getSession().getAttribute(MallConstants.CURRENT_USER);
        if (user == null) {
            throw new UserLoginException();
        }
        return true;
    }

}
